<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改门店产品')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-DeptProduct-edit" th:object="${webDeptProduct}">
        <input name="id" th:field="*{id}" type="hidden">
        <input name="deptId"  type="hidden"  th:field="*{deptId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">门店：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" id="treeName" th:field="*{deptName}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">产品名称：</label>
            <div class="col-sm-8">
                <input name="name" th:field="*{name}" class="form-control" type="text" required>
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label is-required">库存：</label>
            <div class="col-sm-8">
                <input name="stock" th:field="*{stock}" class="form-control" type="text" required>
            </div>
        </div>-->
        <!--<div class="form-group">
            <label class="col-sm-3 control-label is-required">原价：</label>
            <div class="col-sm-8">
                <input name="price" th:field="*{price}" class="form-control" type="text" required>
            </div>
        </div>-->
        <!--<div class="form-group">
            <label class="col-sm-3 control-label is-required">折扣率：</label>
            <div class="col-sm-8">
                <input name="discount" th:field="*{discount}" class="form-control" type="text" required placeholder="如9.8">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">产品图片：</label>
            <div class="col-sm-8">
                <input type="hidden" name="images" th:field="*{images}">
                <div class="file-loading">
                    <input class="form-control file-upload" id="images" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">启用：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}" required>
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">产品详细：</label>
            <div class="col-sm-8">
                <input type="hidden" class="form-control" th:field="*{comment}">
                <div class="summernote" id="comment"></div>
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">备用1：</label>
            <div class="col-sm-8">
                <input name="param1" th:field="*{param1}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备用2：</label>
            <div class="col-sm-8">
                <input name="param2" th:field="*{param2}" class="form-control" type="text">
            </div>
        </div>-->

    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: summernote-js" />
<script th:inline="javascript">
        var prefix = ctx + "system/DeptProduct";
        $("#form-DeptProduct-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-DeptProduct-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

         $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });


        /* 用户管理-修改-选择部门树 */
        function selectDeptTree() {
        	var deptId = $.common.isEmpty($("#deptId").val()) ? "100" : $("#deptId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
		    var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}


        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            var deptId = body.find('#treeId').val();
            $("#deptId").val(deptId);
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    </script>
</body>
</html>